package com.xiaohu.mayi_huiyuan.service;


import com.xiaohu.mayi_huiyuan.entity.Usrs;
import com.xiaohu.mayi_huiyuan.entity.UsrsExample;
import com.xiaohu.mayi_huiyuan.mapper.UsrsMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.List;

@Service
public class LoginService {

     private final static Logger logger = LoggerFactory.getLogger(Exception.class);

    @Autowired
    UsrsMapper usrsMapper;


    public Usrs selectUsrs(Usrs usrs, HttpSession session){
        if(usrs!=null){
            UsrsExample usrsExample=new UsrsExample();
            UsrsExample.Criteria criteria=usrsExample.createCriteria();
            criteria.andNameEqualTo(usrs.getName()).andPassEqualTo(usrs.getPass());
            List<Usrs> usrsList=usrsMapper.selectByExample(usrsExample);
            if(usrsList.size()>0){
               logger.info("管理员登录："+usrsList.get(0).getName()+"/"+usrsList.get(0).getPass());
                session.setAttribute("user",usrsList.get(0));
                session.setMaxInactiveInterval(30 * 60);
                return usrsList.get(0);
            }
        }
        return null;
    }
}
